package morning.cat.springboot.configuration;

import morning.cat.springboot.propertie.CatServiceProperties;
import morning.cat.springboot.service.CatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * XXX
 *
 * @author mengzhang6
 * @date 2018/10/17 19:37
 */
@Configuration
@ConditionalOnClass(CatService.class)
@EnableConfigurationProperties(CatServiceProperties.class)
public class CatAutoConfiguration {


    private final CatServiceProperties properties;

    @Autowired
    public CatAutoConfiguration(CatServiceProperties properties) {
        this.properties = properties;
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "cat.service", value = "enabled", havingValue = "true")
    CatService catService() {
        return new CatService(properties);
    }

}
